//
// Created by vcq on 21/2/9.
//
#pragma once
#include "dbng.hpp"
struct _finishrequire_goal {
    int id;
    int _finishrequire_id;
    int _goal_id;
    int _plan_id;
    string note;
};
REFLECTION(_finishrequire_goal, id, _finishrequire_id, _goal_id, _plan_id, note)

json MGetFinishRequire_Goal(basic_string_view<char> id, basic_string_view<char> _goal_id,
                            basic_string_view<char> _finishrequire_id, basic_string_view<char> _plan_id) {
    string sql = "select * from `_finishrequire_goal` where 1=1 ";
    if (!id.empty()) {
        sql += " and id =";
        sql += id;
    }
    if (!_goal_id.empty()) {
        sql += " and _goal_id =";
        sql += _goal_id;
    }
    if (!_finishrequire_id.empty()) {
        sql += " and _finishrequire_id =";
        sql += _finishrequire_id;
    }
    if (!_plan_id.empty()) {
        sql += " and _plan_id =";
        sql += _plan_id;
    }
    Dao dao;
    nlohmann::json article_list, ret, item;
    auto v = dao.query<_finishrequire_goal>(sql);
    for (auto &o : v) {
        item["id"] = o.id;
        item["_finishrequire_id"] = o._finishrequire_id;
        item["_goal_id"] = o._goal_id;
        item["_plan_id"] = o._plan_id;
        item["note"] = o.note;
        article_list.push_back(item);
    }
    ret["code"] = 0;
    ret["count"] = article_list.size();
    ret["data"] = article_list;
    return ret;
}
void MAddFinishRequire_Goal(const struct _finishrequire_goal& _finishrequire_goal1){
    Dao dao;
    dao.update_object(_finishrequire_goal1);
}
void MDeleteFinishRequire_Goal(basic_string_view<char> id){
    MDeleteAll("_finishrequire_goal",id);
}